var async = require('async');

var concurrencyCount = 0;
var fetchUrl = (url,callback)=>{
    var delay = parseInt((Math.random()*100000000)%2000,10);
    concurrencyCount++;
    console.log('现在的并发数是', concurrencyCount, '，正在抓取的是', url, '，耗时' + delay + '毫秒');
    setTimeout(()=>{
        concurrencyCount--;
        callback(null,url+' html content')
    })
}

var urls = [];
for(var i=0;i<30;i++){
    urls.push('http://datasource_' + i)
}

async.mapLimit(urls,5,(url,callback)=>{
    fetchUrl(url,callback)
},(err,res)=>{
    console.log('final:')
    console.log(res);
})